
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/home/index.vue'
import Main from './views/Main.vue'
import { Indicator } from 'mint-ui';

Vue.use(Router)
const router = new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',//路由的链接地址
      name: 'home', //路由的名称
      component: Home,
      meta: {
        title: '毛孩子宠物'
      },
      redirect: '/main'
    },
    {
      path: "/main",
      name: 'main',
      component: Main,
      children: [
        {
          path: '',
          name: 'home',
          meta: {
            title: '毛孩子宠物'
          },
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "home" */ './views/home/index.vue')
        },
        {
          path: 'mycart',
          name: 'MyCart',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "mycart" */ './views/my-cart/index.vue'),
          meta: {
            title: '购物车'
          }
        },
        {
          path: 'order',
          name: 'order',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "order" */ './views/order/index.vue'),
          meta: {
            title: '订单'
          }
        },
        {
          path: 'my',
          name: 'my',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "my" */ './views/my/index.vue'),
          meta: {
            title: '我的'
          }
        },
        {
          path: 'test',
          name: 'test',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "test" */ './views/test/Test.vue')
        },
      ]
    },
    {
      path: '/detail',
      name: 'detail',
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "detail" */ './views/detail/index.vue'),
      meta: {
        title: '商品详情'
      }
    },
    {
      path: '*',//放到最后一个
      name: '404',
      component: () => import(/* webpackChunkName: "404" */ './views/NotFound.vue')
      // component: NotFound
    }
  ]
})

//全局前置守卫
router.beforeEach((to, from, next) => {
  console.log(to)  // 到哪个页面去？
  console.log(from)  // 从哪个页面来？

  //做一些处理，比如进入到页面的时候显示加载状态
  // Indicator.open('Loading...');
  next()  // 一个回调函数

  //  to    要进入的目标，路由对象
  //  from  当前导航正要离开的路由
  //  next  初步认为是展示页面；（是否显示跳转页面）

})

//全局后置钩子
router.afterEach((to, from) => {
  //关闭加载
  //  Indicator.close()
  // alert("2")
})


export default router

// import Vue from 'vue'
// import Router from 'vue-router'
// import Home from './views/home/index.vue'

// Vue.use(Router)

// export default new Router({
//   // mode: 'history',
//   base: process.env.BASE_URL,
//   routes: [
//     {
//       path: '/',//路由的链接地址
//       name: 'home', //路由的名称
//       component: Home
//     },
//     {
//       path: '/detail',
//       name: 'detail',
//       // route level code-splitting
//       // this generates a separate chunk (about.[hash].js) for this route
//       // which is lazy-loaded when the route is visited.
//       component: () => import(/* webpackChunkName: "about" */ './views/detail/index.vue')
//     },
//     {
//       path: '/mycart',
//       name: 'MyCart',
//       // route level code-splitting
//       // this generates a separate chunk (about.[hash].js) for this route
//       // which is lazy-loaded when the route is visited.
//       component: () => import(/* webpackChunkName: "about" */ './views/my-cart/index.vue')
//     },
//     {
//       path: '/order',
//       name: 'order',
//       // route level code-splitting
//       // this generates a separate chunk (about.[hash].js) for this route
//       // which is lazy-loaded when the route is visited.
//       component: () => import(/* webpackChunkName: "about" */ './views/order/index.vue')
//     },
//     {
//       path: '/my',
//       name: 'my',
//       // route level code-splitting
//       // this generates a separate chunk (about.[hash].js) for this route
//       // which is lazy-loaded when the route is visited.
//       component: () => import(/* webpackChunkName: "about" */ './views/my/index.vue')
//     },
//     {
//       path: '/test',
//       name: 'test',
//       // route level code-splitting
//       // this generates a separate chunk (about.[hash].js) for this route
//       // which is lazy-loaded when the route is visited.
//       component: () => import(/* webpackChunkName: "about" */ './views/test/Test.vue')
//     },
//     {
//       path: '*',//放到最后一个
//       name: '404',
//       component: () => import(/* webpackChunkName: "about" */ './views/NotFound.vue')
//       // component: NotFound
//     }
//   ]
// })


